package com.example.warehouse.bus.dao.persist.repository.impl;

import com.example.warehouse.bus.dao.persist.mapper.BusInportMapper;
import com.example.warehouse.bus.dao.persist.repository.IBusInportRepository;
import com.example.warehouse.bus.pojo.entity.BusInport;
import com.example.warehouse.bus.pojo.param.BusInportUpdateParam;
import com.example.warehouse.bus.pojo.vo.BusInportListItemVO;
import com.example.warehouse.common.pojo.vo.PageData;
import com.example.warehouse.common.security.CurrentPrincipal;
import com.example.warehouse.common.util.PageInfoToPageDataConverter;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Slf4j
@Repository
public class IBusInportRepositoryImpl implements IBusInportRepository {

    @Autowired
    BusInportMapper mapper;

    /**
     * 插入进货数据--增
     * @param busInport 需要插入的实体类
     * @return
     */
    @Override
    public int insert(BusInport busInport) {
        log.debug("开始执行[插入进货数据--增],参数{}",busInport);
        return mapper.insert(busInport);
    }

    /**
     * 根据id删除进货数据--删
     * @param id
     * @param currentPrincipal 需要删除的数据的当事人信息
     * @return
     */
    @Override
    public int deleteById(Long id,CurrentPrincipal currentPrincipal) {
        log.debug("开始执行[根据id删除进货数据--删],ID:{}",currentPrincipal);
        return mapper.deleteById(id,currentPrincipal);
    }

    /**
     * 根据id修改金辉数据--改
     * @param busInportUpdateParam
     * @return
     */
    @Override
    public int updateById(BusInportUpdateParam busInportUpdateParam) {
        log.debug("开始执行[根据id删除进货数据--删],参数类:{}",busInportUpdateParam);
        return mapper.updateById(busInportUpdateParam);
    }




    /**
     * 查询进货(Inport)列表--查
     * @param pageNum 页码
     * @param pageSize 每页记录数
     * @return
     */
    @Override
    public PageData<BusInportListItemVO> list(Integer pageNum, Integer pageSize) {
        log.debug("开始执行[查询进货(Inport)列表--查],页码{},每页记录数{}",pageNum,pageSize);
        PageHelper.startPage(pageNum,pageSize);
        List<BusInportListItemVO> list= mapper.list();
        PageInfo<BusInportListItemVO> pageInfo=new PageInfo<>(list);
        PageData<BusInportListItemVO> pageData = PageInfoToPageDataConverter.convert(pageInfo);
        return pageData;
    }
}
